home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / REALITY / atom / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  6.9 KB  |  226 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /* help.c
  18.  * ------
  19.  *
  20.  * $Revision: 1.6 $
  21.  *
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include <fcntl.h>
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #include <errno.h>
  29. #include <string.h>
  30. #include <gl/gl.h>
  31. #include <gl/device.h>
  32. #include <fmclient.h>
  33. #include <stdlib.h>
  34.  
  35. #include "panel.h"
  36.  
  37. static long HelpYsize, HelpXsize;
  38.  
  39. extern fmfonthandle FontScreen, FontScreen5, FontScreen8, FontScreen10;
  40. extern fmfontinfo FontScreenInfo, FontScreen5Info, FontScreen8Info, 
  41.     FontScreen10Info;
  42.  
  43. long HelpWid = -1;
  44.  
  45. static char **Lines = 0;
  46. static char Text[] = 
  47. "This program uses the sphere primitives to render molecular models.\n\n\
  48. The following describes the functionality of each mouse button.\n\n\
  49. Middle            - Rotate the model objects about its center.\n\
  50. Left              - Scale the model objects.\n\
  51. Left+Middle+Right - Translate the model objects in the z plane.\n\
  52. Left+Middle       - Zoom in or out.\n\n\
  53. The following describes the functionality of each button in the control panel.\n\n\
  54. Help              - Click the help button to exit this window.\n\
  55. Model             - Scroll through the different available molecular models.\n\
  56. Reset             - Reset the model objects to their original size, and put \n\
  57.                     the point of view back in its original position.  If the \n\
  58.                     objects are rotating, pressing the Reset button will stop\n\
  59. \
  60.             them.\n\
  61. Quit              - Quit the program.\n\
  62. Sphere Depth      - Click the left mouse to decrease the tessellation depth\n\
  63.                     level.  Click the middle mouse to increase the tessellation\n\
  64.                     depth level.  The depth range is 1 through 30 inclusively.\n\
  65. Sphere Prim       - Scroll through the different display primitive options.\n\
  66.                     The options are: mesh, polygon, line, and point.\n\
  67. Sphere Type       - Scroll through the different sphere tessellation types.  \n\
  68.                     The options are: oct, icos, bary, cube, and bilin.\n\
  69. Orient            - Toggle orient mode on/off.  When on, the sphere is\n\
  70.                     displayed in a fixed orientation independent of world\n\
  71.                     rotations.\n\
  72. Hemi Sphere       - Toggle hemi sphere mode on/off.\n\
  73. Draw Quick        - Toggle Quick drawing on/off.  In quick-draw mode no \n\
  74.             antialiasing or accumulation processes are done.\n\
  75. Display Bonds     - Toggle the display of the bonds on/off.\n\
  76. Display Atoms     - Toggle the display of the atoms on/off.\n\
  77. Accumulate Atoms  - Toggle the accumulation of the atoms on/off.  In this\n\
  78.                     mode, successive whole-scene antialiasing is done.  When\n\
  79.                     the objects stop moving, the static image is accumulated\n\
  80.                     in the accumulation buffer with slight perturbations.  The\n\
  81.                     way the perturbations of the atoms are done is controlled\n\
  82.                     by roll mode and spin mode.  The final image is\n\
  83.                     antialiased.\n\
  84. Smooth Bonds      - Scroll through the different line smooth levels.  The\n\
  85.                     different levels are: off, on,  and smoother.\n\
  86. End Correct Bonds - Toggle the End Correct mode on/off.  In end correct mode\n\
  87.                     the end point of the bonds are antialiased.  This is\n\
  88.                     visible only if the atoms are not displayed.\n\
  89. Accumulate Bonds  - Toggle the accumulation of the bonds on/off.  This is an\n\
  90.                     alternative way for displaying smooth lines.\n\
  91. Radius            - Use the left mouse button to change the relative size of\n\
  92.                     the atom radii while dragging the vertical bar.  Notice that\n\
  93.                     the bonds are invisible with atoms size 1.0 \n\
  94. Multisample       - This will toggle full scene multisampled antialiasing  \n\
  95.                     on a suitable RealityEngine configuration. \n\
  96. Stereo            - This will toggle in-the-window stereo on \n\
  97.                     a suitable RealityEngine configuration with the proper \n\
  98.                     monitor configuration (setmon 960x680_108s). \n\n\
  99. The Following Keys have useful functionality: \n\n\
  100. O/L               - Will increase/decrease, respectively, \n\
  101.                     the separation for each eye when in stereo.";
  102.  
  103. static int NumLines = 0;
  104.  
  105. void InitHelpWindow();
  106.  
  107. void InitHelp();
  108. void DrawHelp();
  109. void DoEvents();
  110. void DoExit();
  111.  
  112. /****************************************************************************/
  113.  
  114. void InitHelpWindow()
  115. {
  116.     foreground();
  117.     prefsize(HelpXsize, HelpYsize);
  118.     HelpWid = winopen("help");
  119.     if (HelpWid == -1) {
  120.     fprintf(stderr, "no additional graphics windows are available\n");
  121.     DoExit(-1);
  122.     }
  123.     gconfig();
  124. }
  125.  
  126. void CloseHelpWindow()
  127. {
  128.     winclose(HelpWid);
  129.     HelpWid = -1;
  130. }
  131.  
  132. void InitHelp()
  133. {
  134.     char *c;
  135.     int line;
  136.     int num_chars, count;
  137.     int file;
  138.     FILE *fptr;
  139.     int length;
  140.     static initialized = 0;
  141.  
  142.     if (initialized)
  143.     return;
  144.     for(num_chars = 0; Text[num_chars] != 0; num_chars++);
  145.  
  146.     for (c = Text; *c != 0; c++) {
  147.     if (*c == '\n') {
  148.         NumLines++;
  149.     }
  150.     }
  151.     NumLines++;
  152.  
  153.     Lines = (char **) malloc(NumLines * sizeof(char *));
  154.  
  155.     line = 0;
  156.     Lines[line++] = Text;
  157.  
  158.     for (c = Text; *c != 0; c++) {
  159.     if (*c == '\n') {
  160.         *c = 0;
  161.         Lines[line++] = c + 1;
  162.     }
  163.     }
  164.     HelpYsize = NumLines * FontScreen10Info.height + 4;
  165.     HelpXsize = 0;
  166.  
  167.     for (line = 0; line < NumLines; line++) {
  168.     length = fmgetstrwidth(FontScreen10, Lines[line]);
  169.     if (HelpXsize < length)
  170.         HelpXsize = length;
  171.     }
  172.     HelpXsize += 4;
  173.  
  174.     initialized = 1;
  175. }
  176.  
  177. void DrawHelp()
  178. {
  179.     int line;
  180.     long x, y, space;
  181.  
  182.     color(34);
  183.     clear();
  184.     color(WHITE);
  185.  
  186.     fmsetfont(FontScreen10);
  187.     space = FontScreen10Info.height;
  188.     x = 2;
  189.     y = HelpYsize - space;
  190.  
  191.     for (line = 0; line < NumLines; line++) {
  192.     cmov2i(x, y);
  193.     fmprstr(Lines[line]);
  194.     y -= space;
  195.     }
  196. }
  197.  
  198. void DoExitHelp(rc)
  199.     int rc;
  200. {
  201.     if (Lines)
  202.     free(Lines);
  203. }
  204.  
  205. void DoEventsHelp(dev, val)
  206.     long dev;
  207.     short val;
  208. {
  209.     winset(HelpWid);
  210.  
  211.     switch(dev) {
  212.       case REDRAW:
  213.     reshapeviewport();
  214.     DrawHelp();
  215.     break;
  216.  
  217.       case ESCKEY:
  218.     CloseHelpWindow();
  219.     Items[ITEM_HELP].status = SET_PUSHED(0, Items[ITEM_HELP].status);
  220.     break;
  221.  
  222.       default: break;
  223.     }
  224. }
  225.  
  226.